package com.lvmama.pangolin.proxyip.inter.impl;


import org.apache.log4j.Logger;
import org.jsoup.nodes.Document;

import com.lvmama.pangolin.entity.IP;
import com.lvmama.pangolin.proxyip.inter.ProxyIPProcesser;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by NUCTONY on 2016/4/3.
 */
public class APIXiCiDaiLiProcesser implements ProxyIPProcesser {
    private static final Logger logger = Logger.getLogger(APIXiCiDaiLiProcesser.class);


    public List<IP> parseDoc(Document doc) {
        String content = doc.html();
        String[] contents = content.split("\n");
        List<IP> proxyIPVOs = new ArrayList<IP>();
        Date curDate = new Date();
        for (String ipPort : contents) {
            if (ipPort.indexOf(":") > 0) {
                String[] ipPorts = ipPort.split(":");
                IP proxyIPVO = new IP();
                proxyIPVO.setIp(ipPorts[0]);
                proxyIPVO.setIp_port(ipPorts[1]);
                proxyIPVO.setInsert_time(curDate);
                proxyIPVO.setAvailable(1);
                proxyIPVOs.add(proxyIPVO);
            }
        }
        logger.info("proxyIPVOs size = " + proxyIPVOs.size());
        return proxyIPVOs;
    }
}
